const Vuex = require('vuex')

module.exports = new Vuex.Store({
	state: {
		list: {
			data      : [],
			numActive : 0,
			numWaiting: 0,
			numStopped: 0,
		},
		downloadSpeed: 0,
		uploadSpeed  : 0,
		host         : 'http://localhost',
		port         : '6800',
		path         : '/jsonrpc',
		refresh      : 1,
	},
	getters: {

		title ({ list, host, port, path }) {
			return `Active: ${list.numActive} - Waiting: ${list.numWaiting} - Stopped: ${list.numStopped} - ${host}:${port}${path}`
		},
	},
	mutations: {
		connection (state, { host, port, path }) {
			state.host = host
			state.port = port
			state.path = path
		},
		stat (state, { numActive, numWaiting, numStopped, downloadSpeed }) {
			state.list.numActive  = numActive
			state.list.numWaiting = numWaiting
			state.list.numStopped = numStopped
			state.downloadSpeed   = downloadSpeed
		},
	},
})